<template>
  <div class="mobile clearfix">
    <MobileHeader />
    <MobileBanner />

    <div class="one-block clearfix">
      <div class="list clearfix">
        <Ul class="clearfix">
          <li v-for="(item, index) in oneBlock" :key="index" class="clearfix fxl" :class="{ focus: index == 0 }">
            <div class="con bg-white box-shadow clearfix" :class="item.cls" @click="jumpArticleList(item.channelCode)">
              <i class="iconfont" :class="item.titleImg"></i>
              <h2>{{ item.title }}</h2>
              <p>{{ item.en }}</p>
            </div>
          </li>
        </Ul>
      </div>
    </div>

    <div class="box-shadow bg-white clearfix">
      <div class="fxl two-block clearfix" v-for="(gonggao, index) in gonggaos" :key="index">
        <div class="clearfix padding20R padding20L">
          <div class="tit clearfix">
            <h1 class="fxl">{{ gonggao.title }}</h1>
            <p class="fxr more" @click="jumpArticleList(gonggao.channelCode)">
              MORE+
            </p>
          </div>
          <img class="img" :src="gonggao.titleImg" />
          <ul class="li-list clearfix">
            <li class="pos-rel text-wid" v-for="(item, index) in gonggao.sunList" :key="index">
              <a @click="jump(item.id, 'MobileArticle')">
                {{ item.title | ellipsis }}
              </a>
              <span class="pos-abs">{{ item.data }}</span>
            </li>
          </ul>
        </div>
      </div>
    </div>
    <div class="clear hei40"></div>
    <div class="clearfix three-block">
      <div class="clearfix">
        <div class="tit-one clearfix">
          <h1>科室导航</h1>
          <h2>Department navigation</h2>
        </div>
        <div class="clear hei10"></div>
      </div>
      <div class="r-list clearfix" v-for="(dept, index) in depts" :key="index">
        <div class="tit pos-rel clearfix">
          <h1>{{ dept.title }}</h1>
        </div>
        <div class="pos-rel clearfix">
          <Ul class="li-block clearfix">
            <li v-for="(item, index) in dept.sunList" :key="index">
              <span @mouseover="currentDept(item)" @click="jump(item.id, 'MobileArticle')">{{ item.title }}</span>
            </li>
          </Ul>
          <div class="clear hei10"></div>
        </div>
      </div>
    </div>

    <!-- 特色医疗 -->
    <div class="bg-white four-block clearfix">
      <div v-for="(characteristic, index) in characteristics" :key="index">
        <div class="tit clearfix">
          <h1>{{ characteristic.title }}</h1>
          <h2>{{ characteristic.channelNameEn }}</h2>
        </div>
        <div class="clear"></div>
        <Ul class="img-list clearfix">
          <li class="clearfix" v-for="(item, index) in characteristic.sunList" :key="index">
            <div class="con pos-rel clearfix" @click="jump(item.id, 'MobileArticle')">
              <img class="img" :src="item.titleImg" />
              <div class="pos-abs title pad10">
                {{ item.title }}
              </div>
            </div>
          </li>
        </Ul>
      </div>
      <div class="clear hei40"></div>
      <div class="tit clearfix">
        <h1>方位指南</h1>
        <h2>Directions Guide</h2>
      </div>
      <div class="clear hei30"></div>
      <div class="img-address pos-rel clearfix">
        <!-- <img src="../assets/images/adressMobile.jpg"> -->
        <baidu-map class="map" :center="center" :zoom="zoom" @ready="handler">
          <bm-navigation anchor="BMAP_ANCHOR_TOP_LEFT"></bm-navigation>
          <bm-scale anchor="BMAP_ANCHOR_BOTTOM_LEFT"></bm-scale>
          <bm-marker :position="center" :dragging="true" animation="BMAP_ANIMATION_BOUNCE" @click="infoWindowOpen">
            <bm-info-window :show="show" @close="infoWindowClose" @open="infoWindowOpen"></bm-info-window>
          </bm-marker>
        </baidu-map>
      </div>
    </div>

    <MobileFooter />
  </div>
</template>

<script>
import MobileHeader from "./MobileHeader.vue";
import MobileBanner from "./MobileBanner.vue";
import MobileFooter from "./MobileFooter.vue";
import _http from "../httpService";

export default {
  name: "Pc",
  props: {
    msg: String,
  },
  components: {
    MobileHeader,
    MobileBanner,
    MobileFooter,
  },
  data() {
    return {
      currentDeptsContent: null,
      currentDepts: null,
      currentDeptsImg: null,
      show: false,
      center: { lng: 0, lat: 0 },
      zoom: 3,
      oneBlock: [],
      mark: 0,
      imgList: [
        "../assets/images/banner.jpg",
        "../assets/images/banner.jpg",
        "../assets/images/banner.jpg",
      ],
      gonggaos: [],
      depts: [],
      characteristics: [],
      isDisable: false,
      name: "",
      mobile: "",
      content: "",
      num: 1,
    };
  },
  filters: {
    ellipsis(value) {
      if (!value) return "";
      if (value.length > 55) {
        return value.slice(0, 55) + "...";
      }
      return value;
    },
  },

  created() {
    // 初始化加载栏目等数据
    _http
      .get("/website/jcChannel/getChannelListByPc?parentCode=notice")
      .then((response) => {
        console.log(response);
        this.gonggaos = [];
        response.data.result.records.forEach((element) => {
          this.gonggaos.push({
            title: element.title,
            channelCode: element.channelCode,
            titleImg: element.titleImg,
            sunList: element.contentList,
          });
        });
      })
      .catch((error) => console.log(error))
      .finally(() => (this.loading = false));

    _http
      .get("/website/jcChannel/getChannelListByPc?parentCode=fastNavigation")
      .then((response) => {
        this.oneBlock = [];

        response.data.result.records.forEach((element) => {
          this.oneBlock.push({
            title: element.title,
            titleImg: element.titleImg,
            channelCode: element.channelCode,
            cls: element.contentImg,
            en: element.channelNameEn,
            sunList: element.contentList,
          });
        });
      })
      .catch((error) => console.log(error))
      .finally(() => (this.loading = false));

    _http
      .get("/website/jcChannel/getChannelListByPc?parentCode=deptNavigation")
      .then((response) => {
        console.log(response);
        this.depts = [];
        response.data.result.records.forEach((element) => {
          this.depts.push({
            title: element.title,
            sunList: element.contentList,
          });
        });
      })
      .catch((error) => console.log(error))
      .finally(() => (this.loading = false));

    _http
      .get("/website/jcChannel/getChannelListByPc?parentCode=characteristics ")
      .then((response) => {
        console.log(response);
        this.characteristics = [];
        response.data.result.records.forEach((element) => {
          this.characteristics.push({
            title: element.title,
            channelNameEn: element.channelNameEn,
            sunList: element.contentList,
          });
        });
      })
      .catch((error) => console.log(error))
      .finally(() => (this.loading = false));
  },
  mounted() {
    window.addEventListener("scroll", this.handleScroll);
  },
  methods: {
    handler({ BMap, map }) {
      console.log(BMap, map);
      this.center.lng = 116.368475;
      this.center.lat = 39.865296;
      this.zoom = 17;
    },

    infoWindowClose() {
      this.show = false;
    },
    handleScroll() {
      let _this = this;
      var scrollTop =
        window.pageYOffset ||
        document.documentElement.scrollTop ||
        document.body.scrollTop;
      // console.log(scrollTop)
      if (scrollTop) {
        _this.scrollFlag = true;
      } else {
        _this.scrollFlag = false;
      }
    },

    infoWindowOpen() {
      this.show = true;
    },

    jump: function (id, url) {
      this.$router.push({ path: "/" + url + "/" + id });
    },
    jumpArticleList: function (id) {
      this.$router.push({ path: "/MobileArticleList?channelCode=" + id });
    },
    currentDept: function (item) {
      this.currentDepts = item.title;
      this.currentDeptsContent = item.shortTitle;
      this.currentDeptsImg = item.titleImg;
    },

    handler({ BMap, map }) {
      console.log(BMap, map);
      this.center.lng = 116.368475;
      this.center.lat = 39.865296;
      this.zoom = 17;
    },
  },
};
</script>
<style lang="scss" scoped>
@import "../assets/css/mobile.css";

.mobile {
  .one-block {
    .list {
      padding: 0.2rem;

      ul {
        height: 100%;
        width: 100%;

        li {
          width: 50%;
          cursor: pointer;
          text-align: center;
          color: #797979;

          .con {
            margin: 0.2rem;
            padding: 0.4rem 0rem;
            box-shadow: 0px 0px 0.2rem rgba(0, 0, 0, 0.1);

            h2 {
              font-size: 0.3rem;
              height: 0.4rem;
              line-height: 0.4rem;
              padding: 0.2rem 0rem 0rem 0rem;
            }

            i {
              font-size: 0.9rem;
              color: #0eb4b6;
            }

            p {
              color: #a0a0a0;
              font-size: 0.25rem;
              line-height: 0.4rem;
              height: 0.4rem;
              font-weight: bold;
            }
          }
        }

        li:last-child {
          border: 0px;
        }

        li.focus {
          position: relative;
          border: 0px;
          color: #fff;

          i,
          p {
            color: #fff;
          }
        }

        li.focus {
          .con {
            background: -webkit-linear-gradient(90deg,
                #0fb4b6,
                #8ddadc) !important;
            /* Safari 5.1 - 6.0 */
            background: -o-linear-gradient(90deg,
                #0fb4b6,
                #8ddadc) !important;
            /* Opera 11.1 - 12.0 */
            background: -moz-linear-gradient(90deg,
                #0fb4b6,
                #8ddadc) !important;
            /* Firefox 3.6 - 15 */
            background: linear-gradient(90deg,
                #0fb4b6,
                #8ddadc) !important;
            /* 标准的语法（必须放在最后） */
          }
        }
      }
    }
  }

  .two-block {
    width: 100%;
    margin-bottom: 0.2rem;

    .tit {
      padding: 0.15rem 0rem;
      border-bottom: 1px solid #ddd;
      margin-bottom: 0.2rem;

      h1 {
        font-size: 0.3rem;
        color: #333333;
      }

      .more {
        font-size: 0.25rem;
        cursor: pointer;
        line-height: 0.4rem;
        color: #0eb4b6;
      }
    }

    .img {
      width: 100%;
      height: 200px;
    }

    .li-list {
      font-size: 14px;

      li {
        cursor: pointer;
        text-align: left;
        padding: 8px 50px 4px 0px;
        color: #333;

        span {
          right: 0px;
          color: #444;
        }
      }

      li:hover {
        color: #0eb4b6;
        text-decoration: underline;
      }
    }
  }

  .three-block {
    padding: 0rem 0.2rem;

    .tit-one {
      text-align: left;

      h1 {
        font-size: 18px;
        color: #343434;
      }

      h2 {
        color: #999;
        font-size: 14px;
      }
    }

    .img1 {
      margin: 0.2rem 0rem;
      width: 100%;
      height: 6rem;
      background: url("../assets/images/20200513110635616.jpg") no-repeat center center;
    }

    .font {
      left: 0px;
      bottom: 0px;
      right: 0px;
      padding: 10px 10px 20px 20px;
      background: rgba(0, 0, 0, 0.5);
      color: #fff;
      text-align: left;

      h1 {
        font-size: 20px;
        font-weight: normal;
        line-height: 40px;
      }

      h2 {
        font-size: 14px;
        font-weight: normal;
        line-height: 25px;
      }
    }

    .r-list {
      width: 100%;

      .tit {
        border-bottom: 1px solid #dee4ec;
        margin: 0.3rem 0px 0.2rem 0rem;

        h1 {
          font-size: 0.3rem;
          line-height: 0.5rem;
          height: 0.5rem;
          padding-bottom: 0.1rem;
          text-align: left;
          margin-right: 0.4rem;
          color: #7d8794;
        }

        h1.focus {
          color: #222;
        }

        h1.focus:before {
          background: #4cc6c8;
        }

        h1:before {
          content: "";
          position: absolute;
          left: 0px;
          right: 0px;
          bottom: 0px;
          border-radius: 5px 10px 0px 0px;
          height: 4px;
          width: 1.2rem;
          background: transparent;
        }
      }

      .li-block {
        li {
          cursor: pointer;
          float: left;
          width: 50%;
          margin: 0.15rem 0px 0px 0px;

          span {
            display: block;
            margin: 0rem 0.2rem;
            padding: 0.2rem 0rem;
            border: 1px solid #e9ebf0;
            font-size: 0.25rem;
            text-align: center;
            background: #fff;
          }
        }

        li:hover {
          span {
            background: #4fc9ca;
            color: #fff;
            border: 1px solid #4fc9ca;
          }
        }
      }
    }
  }

  .four-block {
    margin: 0.3rem 0rem 0rem 0rem;
    padding: 0.2rem;

    .tit {
      margin: 0rem 0.1rem;

      h1 {
        font-size: 0.3rem;
        line-height: 0.5rem;
        text-align: left;
      }

      h2 {
        font-size: 0.25rem;
        color: #999;
        text-align: left;
      }
    }

    .img-list {
      margin-top: 0.1rem;

      li {
        cursor: pointer;
        float: left;
        width: 50%;

        .con {
          margin: 0.1rem;

          .img {
            width: 100%;
            height: 2.6rem;
          }

          .title {
            display: none;
            left: 0px;
            right: 0px;
            bottom: 2px;
            background: rgba(0, 0, 0, 0.5);
            color: #fff;
            font-size: 14px;
            text-align: center;
            font-weight: bold;
            padding: 10px 0px;
          }
        }

        .con:hover {
          box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);

          .title {
            display: block;
          }
        }
      }
    }

    .img-address {
      img {
        width: 100%;
      }
    }
  }
}
</style>
